%Given Y and Ak, produces a graphviz dot file
m = size(Y,1);
n = size(Y,2);
A = (Ak-diag(diag(Ak)))';
%open a file for writing
fid = fopen('graph.dot','w+');
fprintf(fid,'digraph G {\n graph [fontsize=30, labelloc=t, overlap=false, rankdir=LR, sep=1];');
%add all the Complex nodes
fprintf(fid,'\n subgraph cluster_complexes {  \n node [shape = circle] ');
for i =1:n
		fprintf(fid,'\n\tC%i',i);
end
for i =1:n
		%find the list of parents
	parents = find(A(i,:));
	for j = 1:length(parents);
			%add the directed edge
			fprintf(fid,'\n\t C%i -> C%i [label=%.2f,style=bold]',i,parents(j),A(i,parents(j)));
	end
end

fprintf(fid,'\n}');


%Add the species nodes
fprintf(fid,'\n subgraph cluster_species { \n node [shape=box]');
for i =1:m
		fprintf(fid,'\nS%i[shape=box]',i);
end
fprintf(fid,'\n}');
%add all the species to complex edges
for i =1:m
	neighbors = find(Y(i,:));
	for j=1:length(neighbors)
		%add undirected edges
		fprintf(fid,'\n\t S%i ->  C%i [dir=none,label="%i"]',i,neighbors(j),Y(i,neighbors(j)));
	end
end
fprintf(fid,'\n }');
fclose(fid);

system('sfdp graph.dot > extended.dot');
system('sfdp extended.dot -Teps > g.eps');
